package com.ruoyi.datastatistics.Agreement;

import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * MQTT透传
 */

public class MQTT_HaiAn {
    @Data
    public static class HaiAnEntiy{
        private String name;
        private String value;

    }

    private static String [] arrays = {
            "sys_unix_time","node0101","node0102","node0103","node0104","node0105","node0106",
            "node0107","node0108","node0109","node0110","sys_sn","sys_imei"
    };

    public static HashMap<String,Object> concatenateData(String commandType, Map<String,String> values, String sn){
        List<MQTT_HaiAn.HaiAnEntiy> list = new ArrayList<MQTT_HaiAn.HaiAnEntiy>();

        String snLastSix  = sn.substring(sn.length() - 6);//sn后六位
        switch (commandType){
            case "0"://开关阀
                String value = values.get("isOpen");
                MQTT_HaiAn.HaiAnEntiy haiAnEntiy109 = new MQTT_HaiAn.HaiAnEntiy();
                MQTT_HaiAn.HaiAnEntiy haiAnEntiy110 = new MQTT_HaiAn.HaiAnEntiy();
                if(value.equals("0")){//开
                    haiAnEntiy109.setValue("1");
                    haiAnEntiy109.setName(arrays[9] + snLastSix);

                    haiAnEntiy110.setValue("0");
                    haiAnEntiy110.setName(arrays[10] + snLastSix);
                }else{//关
                    haiAnEntiy109.setValue("0");
                    haiAnEntiy109.setName(arrays[9] + snLastSix);

                    haiAnEntiy110.setValue("1");
                    haiAnEntiy110.setName(arrays[10] + snLastSix);
                }
                list.add(haiAnEntiy109);
                list.add(haiAnEntiy110);
                break;
        }
        HashMap<String,Object> mapVer = new HashMap<String,Object>();
        mapVer.put("Ver","1.0.1");
        mapVer.put("dir","down");
        mapVer.put("id","sys_sn");
        mapVer.put("w_data",list);
        HashMap<String,Object> map = new HashMap<String,Object>();
        map.put("rw_prot",mapVer);
        return map;
    }

}


